﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;

    public class DailyInvPalletRptQuery : BasePage
    {
        protected Button btnSearch;
        protected DropDownList ddlOwnerIDOper;
        protected DropDownList ddlSkuIDOper;
        protected HtmlForm F15650;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlHead Head1;
        protected HtmlImage img1;
        protected Label lblEndDate;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblQuery;
        protected Label lblSkuID;
        protected Label lblStartDate;
        protected HtmlLink mycss;
        protected TextBox txtEndDate;
        protected TextBox txtOwnerID;
        protected TextBox txtSkuID;
        protected TextBox txtStartDate;

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.lblMsg.Text = string.Empty;
            if (string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9230_002");
            }
            else
            {
                DateTime dt = new DateTime();
                if (!DateTime.TryParse(this.txtStartDate.Text.Trim(), out dt))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9230_007");
                }
                else if (string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9230_003");
                }
                else
                {
                    dt = new DateTime();
                    if (!DateTime.TryParse(this.txtEndDate.Text.Trim(), out dt))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F9230_007");
                    }
                    else if (this.DateDiff(Convert.ToDateTime(this.txtStartDate.Text.Trim()), Convert.ToDateTime(this.txtEndDate.Text.Trim())) > 0x1f)
                    {
                        this.lblMsg.Text = "日期时间段不能超过31天！";
                    }
                    else
                    {
                        base.Server.Transfer(string.Format("DailyInvPalletRptList.aspx?action={0}", base.UrlEncode(this.hdnActionID.Value.Trim())), false);
                    }
                }
            }
        }

        private int DateDiff(DateTime dt1, DateTime dt2)
        {
            TimeSpan startTS = new TimeSpan(dt1.Ticks);
            TimeSpan endTS = new TimeSpan(dt2.Ticks);
            return startTS.Subtract(endTS).Duration().Days;
        }

        private void LoadData()
        {
            base.InitQueryDDL(this.ddlOwnerIDOper, 0);
            base.InitQueryDDL(this.ddlSkuIDOper, 0);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        public string EndDate
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
                {
                    return (Convert.ToDateTime(this.txtEndDate.Text).ToString("yyyy-MM-dd") + " 23:59:59");
                }
                return "";
            }
        }

        public string OwnerID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtOwnerID.Text.Trim(), this.ddlOwnerIDOper.SelectedValue);
                }
                return "";
            }
        }

        public string SkuID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtSkuID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtSkuID.Text.Trim(), this.ddlSkuIDOper.SelectedValue);
                }
                return "";
            }
        }

        public string StartDate
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
                {
                    return (Convert.ToDateTime(this.txtStartDate.Text).ToString("yyyy-MM-dd") + " 00:00:00");
                }
                return "";
            }
        }
    }
}

